/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LOTTIE_TURBO_LOTTIE_RENDER_GPU_H
#define LOTTIE_TURBO_LOTTIE_RENDER_GPU_H
#include "color.h"
#include "native_drawing/drawing_gpu_context.h"
#include "native_drawing/drawing_surface.h"
#include "render/lottie_render_layer.h"
#include "render/lottie_render_nativewindow.h"

namespace LottieTurbo {

class LottieGpuFun {
private:
    void *funcHandle_;

    LottieGpuFun();

    ~LottieGpuFun();

    LottieGpuFun(const LottieGpuFun &) = delete;

    LottieGpuFun &operator=(const LottieGpuFun &) = delete;

    LottieGpuFun(LottieGpuFun &&) = delete;

    LottieGpuFun &operator=(LottieGpuFun &&) = delete;

    typedef OH_Drawing_GpuContext *(*GpuCreate)(void);

    typedef void (*GpuDestroy)(OH_Drawing_GpuContext *gpuContext);

    typedef OH_Drawing_Surface *(*GpuSurface)(OH_Drawing_GpuContext *gpuContext, OH_Drawing_Image_Info imageInfo,
                                              void *window);

    typedef OH_Drawing_Surface *(*GpuSurfaceFromContext)(OH_Drawing_GpuContext *gpuContext, bool flag,
                                                         OH_Drawing_Image_Info imageInfo);

    typedef OH_Drawing_ErrorCode (*GpuFlash)(OH_Drawing_Surface *surface);

    GpuSurface funcGpuSurface_ = nullptr;
    GpuCreate funcGpuCreate_ = nullptr;
    GpuDestroy funcGpuDestroy_ = nullptr;
    GpuSurfaceFromContext funcGpuSurfaceFromContext_ = nullptr;
    GpuFlash funcGpuFlash_ = nullptr;

public:
    static LottieGpuFun &GetInstance();

    /**
     * Surface创建
     * @param gpuContext
     * @param imageInfo 图片信息
     * window 窗口
     */
    OH_Drawing_Surface *RenderGpuSurface(OH_Drawing_GpuContext *gpuContext, OH_Drawing_Image_Info imageInfo,
                                         void *window);
    /**
     * GpuContext创建
     */
    OH_Drawing_GpuContext *RenderGpuCreate();

    /**
     * GpuContext销毁
     * @param gpuContext
     */
    void RenderGpuDestroy(OH_Drawing_GpuContext *gpuContext);

    /**
     * 创建离屏Surface
     * @param gpuContext
     * @param flag 是否计入缓存预算
     * @param imageInfo 图片信息
     */
    OH_Drawing_Surface *RenderGpuSurfaceFromContext(OH_Drawing_GpuContext *gpuContext, bool flag,
                                                    OH_Drawing_Image_Info imageInfo);
    /**
     * 屏幕渲染
     * @param surface
     */
    void RenderGpuFlash(OH_Drawing_Surface *surface);
};

} // namespace LottieTurbo
#endif // LOTTIE_TURBO_LOTTIE_RENDER_GPU_H
